package org.wattdepot.cli.command;

import static org.junit.Assert.assertTrue;
import org.junit.Test;

/**
 * Tests the carbonContent method with various inputs for correct outputs.
 * 
 * @author Alex Kan and Kelvin Green
 * @version 2.0
 */
public class TestWattDepotCarbonContent {
  WattDepotCommand commandInstance;
  String[] commandArray;
  String userInput;

  /**
   * Test WattDepotCarbonContent method for 2 correct outputs and errors on 2 inputs.
   * 
   * Test (correct) carboncontent SIM_WAIAU_8 2009-11-15T12:00:00.000-10:00 sampling-interval 30:
   * 1800 Test (correct) carboncontent SIM_IPP 2009-11-15T12:00:00.000-10:00 sampling-interval 30:
   * 2083 Test (error) carboncontent SIM_IPP 2009-11-15T12:00:00.000-10:00 sampling-interval:
   * carboncontent {source} {timestamp} sampling-interval {interval} Test (error) carboncontent
   * SIM_IPP 2009-11-1512:00:00.000-10:00 sampling-interval 30: Not a valid timestamp.
   */
  @Test
  public void testCarbonContent() {
    WattDepotCommand.connect("http://server.wattdepot.org:8182/wattdepot/");
    commandInstance = new WattDepotCarbonContentCommand();
    userInput = "carboncontent SIM_WAIAU_8 2009-11-15T12:00:00.000-10:00" 
      + " sampling-interval 30";
    commandArray = userInput.split(" ");
    assertTrue("Check for carbon content", 
        commandInstance.doCommand(commandArray).contains("1800"));

    commandInstance = new WattDepotCarbonContentCommand();
    userInput = "carboncontent SIM_IPP 2009-11-15T12:00:00.000-10:00 sampling-interval 30";
    commandArray = userInput.split(" ");
    assertTrue("Check for carbon content", 
        commandInstance.doCommand(commandArray).contains("2083"));

    commandInstance = new WattDepotCarbonContentCommand();
    userInput = "carboncontent SIM_IPP 2009-11-15T12:00:00.000-10:00 sampling-interval";
    commandArray = userInput.split(" ");
    assertTrue("Check for error", commandInstance.doCommand(commandArray).contains(
        "carboncontent {source} {timestamp} " + "sampling-interval {interval}"));

    commandInstance = new WattDepotCarbonContentCommand();
    userInput = "carboncontent SIM_IPP 2009-11-1512:00:00.000-10:00 sampling-interval 30";
    commandArray = userInput.split(" ");
    assertTrue("Check for error", commandInstance.doCommand(commandArray).contains(
        "Not a valid timestamp."));

  }
}
